<?php


namespace app\common\models;


use app\common\traits\BaseModelOptionTrait;
use Carbon\Carbon;
use think\Model;

class UserWithdraw extends Model
{
    use BaseModelOptionTrait;

    protected $table = 'xiangji_user_withdraws';
    // 自动维护时间戳
    protected $autoWriteTimestamp = true;

    protected $type = [
        'audit_time'    => 'timestamp',
        'payment_time'  => 'timestamp'
    ];

    public static function onBeforeInsert($withdraw)
    {
        // 生成提现单号
        $withdraw->trade_no = 'TX' . Carbon::now()->getPreciseTimestamp(3) . mt_rand(1000, 9999);
    }

    // 该钱包的所属用户
    public function user()
    {
        return $this->belongsTo(User::class);
    }
}
